<template>
  <div class="home">
    <!-- 搜索框 -->
    <div class="search_box">
      <van-search placeholder="请输入搜索关键词" class="search">
        <template #left>
          <div class="cityList">
            上海
            <van-icon name="arrow-down" />
          </div>
        </template>
      </van-search>
      <van-icon name="location-o" color="#fff"/>
    </div>
    <!-- /搜索框 -->

    <!-- 轮播图 -->
    <div class="swipe">
      <van-swipe :autoplay="3000">
        <van-swipe-item v-for="item in lunBoTu" :key="item.id">
          <img :src="'http://liufusong.top:8080'+item.imgSrc" alt="">
        </van-swipe-item>
      </van-swipe>
    </div>
    <!-- /轮播图 -->

    <!-- 导航 -->
    <div class="grid">
      <van-grid :border='false'>
        <van-grid-item icon="" text="整租" />
        <van-grid-item icon="" text="合租" />
        <van-grid-item icon="" text="地图找房" />
        <van-grid-item icon="" text="去出租" to="/rent/add"/>
      </van-grid>
    </div>
    <!-- /导航 -->

    <!-- 租房小组 -->
    <div class="group">
        <h3 class="group_title">
          租房小组
          <span class="more">更多</span>
        </h3>
        <div class="am-grid">
          <van-grid direction="horizontal" :column-num="2" :border='false'>
            <van-grid-item v-for="item in zuFangZi" :key="item.id" :icon="'http://liufusong.top:8080'+item.imgSrc">
              <template #text>
                <div>
                  <p>{{item.title}}</p>
                  <p>{{item.desc}}</p>
                </div>
              </template>
            </van-grid-item>
          </van-grid>
        </div>
      </div>
    <!-- /租房小组 -->
  </div>
</template>

<script>
import { getLunBo, getZuFang } from '@/api/home'
export default {
  data () {
    return {
      value: '',
      lunBoTu: [],
      zuFangZi: []
    }
  },

  created () {
    this.getLunBoTu()
    this.getZuFangZi()
  },

  methods: {
    async getLunBoTu () {
      try {
        const res = await getLunBo()
        console.log(res)
        this.lunBoTu = res
      } catch (err) {
        console.log('获取失败')
      }
    },
    async getZuFangZi () {
      try {
        const res = await getZuFang()
        console.log(res)
        this.zuFangZi = res
      } catch (err) {
        console.log('获取失败')
      }
    }
  }
}
</script>

<style scoped lang='less'>
 .home{
  position: relative;
  .search_box{
    position: absolute;
    top: 25px;
    width: 100%;
    padding: 0 10px;
    box-sizing: border-box;
    display: flex;
    justify-content: space-between;
    z-index: 2;
    .search{
      width: 100%;
      height: 34px;
      margin: 0 10px;
      padding: 5px  5px 5px 8px;
      border-radius: 3px;
      background-color: #fff;
    }
    .van-search__content{
      background-color: transparent;
    }
    .cityList{
      font-size: 14px;
    }
    .van-icon{
      line-height: 34px;
    }
  }
  .swipe{
    img{
      width: 375px;
      height: 213px;
      display: block;
    }
  }
  .grid{
    /deep/.van-icon__image{
      width: 60px;
      height: 60px;
    }
    /deep/.van-grid-item__text{
      font-size: 14px;
      font-weight: 400;
      color: #000;
    }
  }
  .group{
    overflow: hidden;
    background-color: #f6f5f6;
    padding:0 10px;
    width: 100%;
    box-sizing: border-box;
    .group_title{
      display: flex;
      justify-content: space-between;
      margin: 15px 0 15px 10px;
      font-size: 15px;
      .more{
        color: #787878;
        font-style: 14px;
        font-weight: 400;
      }
    }
    .van-grid-item{
      width: 172px;
      height: 60px;
      padding: 5px;
      margin-bottom: 10px;
      /deep/.van-grid-item__content--center{
        justify-content: space-evenly;
      }
      /deep/.van-icon__image{
        width: 50px;
        height: 50px;
      }
      p{
        font-size: 12px;
        margin: 0;
      }
    }
  }
}
</style>
